<?php
/**
 * 熵巡 - 企业级氚云OpenAPI数据管理平台
 * 开发归属 Alyr.net
 * 表单管理内容页 - 表单增删改查、令牌管理
 * 尊重劳动成果是一种美德
 */
?>
<!-- 表单管理内容页面 -->
<div class="schema-manage-panel">
    <div class="schema-actions">
        <button id="add-schema-btn" class="btn btn-primary" onclick="showAddSchemaModal()">
            新增表单
        </button>
        <button id="refresh-schema-btn" class="btn btn-secondary" onclick="loadSchemaList()">
            刷新列表
        </button>
    </div>
    
    <div id="schema-list" class="schema-list">
        <!-- 表单列表将通过JS动态加载 -->
    </div>
    
    <div id="schema-pagination" class="pagination" style="display:none;">
        <!-- 分页将通过JS动态生成 -->
    </div>
</div>

<!-- 新增/编辑表单模态框 -->
<div id="schemaModal" class="modal" style="display:none;">
    <div class="modal-content">
        <div class="modal-header">
            <h3 id="schemaModalTitle">新增表单</h3>
            <span class="close" onclick="hideSchemaModal()">&times;</span>
        </div>
        <div class="modal-body">
            <form id="schemaForm">
                <input type="hidden" id="schema-index" value="">
                
                <div class="form-group">
                    <label for="schema-name">表单名称: <span class="required">*</span></label>
                    <input type="text" id="schema-name" name="schema_name" class="form-input" required placeholder="例如：客户订单">
                </div>
                
                <div class="form-group">
                    <label for="schema-code">表单编码: <span class="required">*</span></label>
                    <input type="text" id="schema-code" name="schema_code" class="form-input" required placeholder="例如：D28420682b29057b1f241e2a0fd293f1ebd90b9">
                    <small class="form-help">40位氚云表单编码，D开头后跟39位十六进制字符</small>
                </div>
                
                <div class="form-group">
                    <label for="schema-image-fields">图片字段:</label>
                    <input type="text" id="schema-image-fields" name="image_fields" class="form-input" placeholder="多个字段用逗号分隔，例：F0000007,F0000012">
                    <small class="form-help">请输入图片字段编码，多个用英文逗号分隔</small>
                </div>
                
                <div class="form-group">
                    <label for="schema-attachment-fields">附件字段:</label>
                    <input type="text" id="schema-attachment-fields" name="attachment_fields" class="form-input" placeholder="多个字段用逗号分隔，例：F0000008,F0000013">
                    <small class="form-help">请输入附件字段编码，多个用英文逗号分隔</small>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" id="delete-schema-btn" class="btn btn-secondary" onclick="deleteCurrentSchema()" style="display:none;">删除</button>
            <button type="button" class="btn btn-primary" onclick="saveSchema()">保存</button>
        </div>
    </div>
</div>

<!-- 令牌管理模态框 -->
<div id="tokenModal" class="modal" style="display:none;">
    <div class="modal-content">
        <div class="modal-header">
            <h3>表单令牌管理</h3>
            <span class="close" onclick="hideTokenModal()">&times;</span>
        </div>
        <div class="modal-body">
            <div class="form-group">
                <label>令牌ID:</label>
                <div class="token-display">
                    <input type="text" id="display-token-id" class="form-input" readonly onclick="this.select()">
                    <button class="btn btn-secondary" onclick="regenerateTokenId()">随机</button>
                    <button class="btn btn-secondary" onclick="copyToClipboard('display-token-id')">复制</button>
                </div>
            </div>
            
            <div class="form-group">
                <label>令牌密钥:</label>
                <div class="token-display">
                    <input type="text" id="display-token-secret" class="form-input" readonly onclick="this.select()">
                    <button class="btn btn-secondary" onclick="regenerateTokenSecret()">随机</button>
                    <button class="btn btn-secondary" onclick="copyToClipboard('display-token-secret')">复制</button>
                </div>
            </div>
            
            <div class="alert alert-warning">
                <strong>注意:</strong> 请妥善保管令牌信息，用于前端API调用身份验证。
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" id="delete-token-btn" class="btn btn-secondary" onclick="deleteCurrentToken()" style="display:none; margin-right: auto;">删除令牌</button>
            <button type="button" class="btn btn-primary" onclick="saveTokenChanges()">保存</button>
        </div>
    </div>
</div>
